#include <climits>
#include <iostream>
#include <iomanip>
using namespace std;
bool is_leap_year(int year)
{
    return (year%4==0 && year%100!=0)|| (year%400==0);
}

int GetMonthDay(int year,int month)
{
    static int months_arr[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    if (month==2 && is_leap_year(year))
        return 29;
    else
        return months_arr[month]; 
}

class Date
{
public:
    Date(int year,int month,int day)
        :_year(year)
        ,_month(month)
        ,_day(day)
    {}
    Date& operator+(int days)
    {
      _day+=days;
      while(_day>GetMonthDay(_year,_month))
      {
        _day-=GetMonthDay(_year,_month);
        _month++;
         if (_month==13)
         {
            _year++;
            _month=1;
         }
      } 
      return *this;
    }

    int _year;
    int _month;
    int _day;
};

ostream& operator<<(ostream& out,Date& d)
{
    out<<d._year<<"-";
    cout<<setw(2)<<setfill('0')<<d._month<<"-";
    cout<<setw(2)<<setfill('0')<<d._day<<endl;
    return out;
}

int main() 
{
    int days,year,month,day,m;
    cin>>m;
    while (m--)
    {
        cin>>year>>month>>day>>days;
        Date d(year,month,day);
        cout<<(d+days);
    }
    return 0;
}
